package com.lw.leetcode.test;

import java.util.Arrays;

/**
 * @Author liw
 * @Date 2021/3/31 17:35
 * @Version 1.0
 */
public class Backtracking {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        int[] b = new int[arr.length];
        aa(arr, 0, b);
    }

    private static void aa(int[] arr, int index, int[] printArr) {

        int length = arr.length;
        if (length == 0) {
            System.out.println(Arrays.toString(printArr));
            return;
        }
        for (int i = 0; i < length; i++) {
            printArr[index] = arr[i];
            int[] arr2 = copy(arr, i);
            aa(arr2, index + 1, printArr);
        }
    }

    // 回溯
    private static int[] copy(int[] arr, int n) {
        int length = arr.length;
        int[] copyArr = new int[length - 1];
        int c = 0;
        for (int i = 0; i < length; i++) {
            if (i != n) {
                copyArr[c++] = arr[i];
            }
        }
        return copyArr;
    }

}
